<?php
/**
 * @file
 * Returns the HTML for a single Drupal page.
 *
 * Complete documentation for this file is available online.
 * @see https://drupal.org/node/1728148
 */
?>

<?php print render($page['navigation']); ?>

<div id="page">
    <?php print render($page['help']); ?>

	<header class="header" id="header" role="banner">
		<div class="wrapper">

			<div class="menu-trigger"></div>
			<div class="search-trigger"></div>
			<div class="font-size-trigger"></div>
			<?php if ($logo): ?>
			<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" class="header__logo" id="logo">
                <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" class="header__logo-image" />
			</a>
			<?php endif; ?>

			<?php print render($page['header']); ?>

		</div>
	</header>

	<div id="main">
        <?php print $messages; ?>
        <?php print render($page['highlighted']); ?>

        <?php if ($title): ?>
        <h1 class="page__title title element-invisible" id="page-title"><?php print $title; ?></h1>
        <?php endif; ?>

        <?php print $breadcrumb; ?>

        <div id="content" class="column region-content" role="main">
            <article data-nid="<?php print $node->nid; ?>" class="app">
                <div class="wrapper">
                    <div class="article-inner">
                        <?php print render($tabs); ?>
                        <?php if ($action_links): ?>
                        <ul class="action-links"><?php print render($action_links); ?></ul>
                        <?php endif; ?>
                        <h2 class="node-title"><?php print $title?></h2>

                        <div class="article-top">
                            <?php echo jessica_thm_author_author_section($node); ?>
                            <div class="article-share-amount">
                                <?php if (!empty($node->field_social_count)): ?>
                                    <strong><?php print $node->field_social_count['und'][0]['value']; ?></strong>
                                <?php else: ?>
                                    <strong>0</strong>
                                <?php endif; ?>SHARES</div>
                            <div class="article-share-action">
                                <a href="#" class="article-share-close icon icon-cross"></a>
                                <a href="#" class="article-share-icon icon icon-facebook"></a>
                                <a href="#" class="article-share-icon icon icon-sina"></a>
                                <a href="#" class="article-share-icon icon icon-whatsapp"></a>
                                <a href="#" class="article-share-icon icon icon-pinterest"></a>
                                <a href="#" class="article-share-icon icon icon-email"></a>
                                <a href="#" class="article-share-toggle icon icon-share"></a>
                            </div>
                        </div>

                        <div id="slideshow"></div>

                        <div class="si-brand-top">
                            <h4><?php if(!empty($node->field_item_brand)): ?>
                                    <?php print $node->field_item_brand['und'][0]['taxonomy_term']->name; ?>
                                <?php endif; ?>
                            </h4>
                            <?php if(!empty($node->field_item_price)): ?>
                                <h2>$<?php print $node->field_item_price['und'][0]['value']; ?></h2>
                            <?php endif; ?>
                            <div class="si-desc">
                                <?php if(! empty($node->body) && !empty($node->body['und'])): ?>
                                <section>
                                    <h3>Item Description</h3>
                                    <div class="field-body">
                                        <?php if(! empty($node->body) && !empty($node->body['und'])): ?>
                                            <?php print $node->body['und'][0]['safe_value']; ?>
                                        <?php endif; ?>
                                    </div>
                                </section>
                                <?php endif; ?>
                                <section>
                                    <h3>Item Details</h3>
                                    <table>
                                        <tr>
                                            <td class="si-desc-label">Category</td>
                                            <td class="si-desc-content">
                                                <?php if(!empty($node->field_item_category['und'])): ?>
                                                    <?php if(isset($node->field_item_category['und'][0]['taxonomy_term']->parent) && !empty($node->field_item_category['und'][0]['taxonomy_term']->parent)): ?>
                                                        <?php $parent_term = taxonomy_term_load($node->field_item_category['und'][0]['taxonomy_term']->parent[0]); ?>
                                                        <?php if($parent_term != null): ?>
                                                            <a rel="nofollow" href="/stylebook/item?cat=<?php print $parent_term->tid; ?>"><?php print $parent_term->name ?></a> > <a href="/stylebook/item?cat=<?php print $node->field_item_category['und'][0]['tid']; ?>"><?php print $node->field_item_category['und'][0]['taxonomy_term']->name; ?></a>
                                                        <?php else: ?>
                                                            <a rel="nofollow" href="/stylebook/item?cat=<?php print $node->field_item_category['und'][0]['tid']; ?>"><?php print $node->field_item_category['und'][0]['taxonomy_term']->name; ?></a>
                                                        <?php endif; ?>
                                                    <?php else: ?>
                                                        <a rel="nofollow" href="/stylebook/item?cat=<?php print $node->field_item_category['und'][0]['tid']; ?>"><?php print $node->field_item_category['und'][0]['taxonomy_term']->name; ?></a>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="si-desc-label">Size</td>
                                            <td class="si-desc-content">
                                                <?php if (!empty($node->field_item_size) && !empty($node->field_item_size['und'])): ?>
                                                    <?php print strtoupper($node->field_item_size['und'][0]['taxonomy_term']->name) ?>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="si-desc-label">Keywords</td>
                                            <td class="si-desc-content">
                                                <div class="field-tags">
                                                    <?php print views_embed_view('styling_items', 'keywords'); ?>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </section>
                            </div>

                            <?php if (!empty($node->field_item_buy_link) && !empty($node->field_item_buy_link['und'][0]['safe_value'])): ?>
                                <div class="si-brand-buy">
                                    <a href="<?php print $node->field_item_buy_link['und'][0]['safe_value']; ?>">
                                        <strong>
                                            Buy
                                            <?php if(!empty($node->field_item_shop_name)): ?>
                                                at <?php print $node->field_item_shop_name['und'][0]['value']; ?>
                                            <?php endif; ?>
                                        </strong>
                                        <?php if(!empty($node->field_item_brand)): ?>
                                            <br>(<?php print $node->field_item_brand['und'][0]['taxonomy_term']->name; ?>)
                                        <?php endif; ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>

                        <?php print views_embed_view('styling_items', 'looking_for_more'); ?>

                        <?php
                            print _get_block('scmedia_fb_comment','facebook_comment');
                        ?>

                        <div class="sa-morelook">
                            <a href="/stylebook/item">More item</a>
                        </div>

                        <div class="si-brand-intro">
                            <h4>Brand introduction</h4>
                            <h3>
                                <?php if(!empty($node->field_item_brand)): ?>
                                    <?php print $node->field_item_brand['und'][0]['taxonomy_term']->name; ?>
                                <?php endif; ?>
                            </h3>
                            <p>
                                <?php if(!empty($node->field_item_brand)): ?>
                                    <?php print $node->field_item_brand['und'][0]['taxonomy_term']->description; ?>
                                <?php endif; ?>
                            </p>
                            <?php if( !empty($node->field_item_brand)): ?>
                                <a rel="nofollow" href="/stylebook/item?brand=<?php print $node->field_item_brand['und'][0]['tid']; ?>" class="icon icon-search">Search items from this brand</a>
                            <?php endif; ?>
                            <?php if( !empty($node->field_item_brand) && !empty($node->field_item_brand['und'][0]['taxonomy_term']->field_brand_official_website)): ?>
                                <a rel="nofollow" href="<?php print $node->field_item_brand['und'][0]['taxonomy_term']->field_brand_official_website['und'][0]['value']; ?>" class="icon icon-window">Visit this brand's official web site</a>
                            <?php endif; ?>
                        </div>

                        <?php if(!empty($node->field_item_brand)): ?>
                            <?php if(!empty($node->field_item_brand['und'][0]['taxonomy_term'])): ?>
                                <?php if(!empty($node->field_item_brand['und'][0]['taxonomy_term']->field_brand_where_to_buy)): ?>
                                    <div class="si-map">
                                        <h3>Where to buy</h3>
                                        <?php print $node->field_item_brand['und'][0]['taxonomy_term']->field_brand_where_to_buy['und'][0]['value']; ?>
                                    </div>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endif; ?>

                        <div class="sa-right-banner">
                            <?php print bck_render_('ads-article-300x250'); ?>
                        </div>
                        <?php $view = _get_related_style_articles_mobile();?>
                        <?php if (count($view->result) > 0): ?>
                            <div class="sa-suggestion">
                                <h3>Style you may like</h3>
                                <?php foreach ($view->result as $result): ?>
                                    <?php $entity = $result->_field_data['nid']['entity']; ?>
                                    <?php $items = $result->field_field_styling_item; ?>
                                    <a href="<?php print base_path() . drupal_get_path_alias('node/' . $result->nid); ?>">
                                        <?php if (! empty($entity->field_image)): ?>
                                            <img src="<?php print image_style_url('related_styling_article_thumbnail', $entity->field_image['und'][0]['uri']); ?>" alt="<?php print $entity->field_image['und'][0]['alt']; ?>" title="<?php print $entity->field_image['und'][0]['title']; ?>" />
                                        <?php endif; ?>
                                        <!--<div class="sa-suggestion-palette">
                                            <?php /*if (! empty($items)): */?>
                                                <?php /*foreach($items as $item): */?>
                                                    <?php /*$fc_id = $item['raw']['value']; */?>
                                                    <?php /*if(! empty($item['rendered']['entity']['field_collection_item'][$fc_id]['field_styling_item_id']['#items'][0]['entity']->field_item_colour)) : */?>
                                                        <?php /*$term = taxonomy_term_load($item['rendered']['entity']['field_collection_item'][$fc_id]['field_styling_item_id']['#items'][0]['entity']->field_item_colour['und'][0]['tid']); */?>
                                                        <?php /*if ($term->field_hex_colour_code['und'][0]['safe_value'] != 'OTHER'): */?>
                                                            <div style="background-color: <?php /*print $term->field_hex_colour_code['und'][0]['safe_value']; */?>;"></div>
                                                        <?php /*else: */?>
                                                            <div class="other-color"></div>
                                                        <?php /*endif; */?>
                                                    <?php /*endif; */?>
                                                <?php /*endforeach; */?>
                                            <?php /*endif; */?>
                                        </div>-->
                                    </a>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>
                    </div>

                    <?php //print render($page['content']); ?>
                    <?php //print $feed_icons; ?>
                </div>
            </article>
        </div>
        <?php //print render($page['below_content']); ?>
        <?php print render($page['bottom']); ?>
        <?php print render($page['footer']); ?>
	</div>

</div>

<?php print render($page['popup']); ?>
<?php print render($page['overlay']); ?>
<?php print render($page['hidden']); ?>
